package com.intellagric.controller.module.recommend;

import com.intellagric.agriecom.module.recommend.RecommendColumnServiceIN;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.RecommendColumn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * @Auther: zhy
 * @Date: 2019/5/10
 * @Description: 推荐栏位管理
 */
@Controller
public class RecommendColumnController {

    @Autowired
    private RecommendColumnServiceIN recommendColumnService;

    /**
     * 添加荐栏位信息
     * @Param recommendColumn
     * @return ResponseMessage
     */
    @RequestMapping("/recommend/column/add")
    @ResponseBody
    public ResponseMessage add(RecommendColumn recommendColumn) {
        recommendColumn.setCreatedDate(new Date());
        if (recommendColumnService.addRecommendColumn(recommendColumn) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }


    /**
     * 删除荐栏位信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/recommend/column/delete")
    @ResponseBody
    public ResponseMessage delete(int id) {
        if (recommendColumnService.deleteRecommendColumn(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改荐栏位信息
     * @Param recommendColumn
     * @return ResponseMessage
     */
    @RequestMapping("/recommend/column/edit")
    @ResponseBody
    public ResponseMessage edit(RecommendColumn recommendColumn) {
        if (recommendColumnService.editRecommendColumn(recommendColumn) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询荐栏位信息
     * @return RecommendColumn
     */
    @RequestMapping("/recommend/column/{id}")
    @ResponseBody
    public RecommendColumn get(@PathVariable int id) {
        return recommendColumnService.queryRecommendColumnById(id);
    }


    /**
     * 查询荐栏位信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/recommend/column/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        List<RecommendColumn> recommendColumnList = recommendColumnService.queryRecommendColumnList();
        return LayuiDataGridResult.success().add(recommendColumnList,recommendColumnList.size());
    }

    /**
     * 分页查询荐栏位信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/recommend/column/page")
    @ResponseBody
    public LayuiDataGridResult getPage() {
        List<RecommendColumn> recommendColumnList = recommendColumnService.queryRecommendColumnList();
        return LayuiDataGridResult.success().add(recommendColumnList,recommendColumnList.size());
    }




}
